package com.example.wan1;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

/***
 * 用来测试inflate
 */
public class TestActivity extends AppCompatActivity {

    private RelativeLayout mRl;
    private TextView tv;
    private int i = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);

        mRl = findViewById(R.id.inflate_container);
        tv = findViewById(R.id.removeall);
        Log.i("zxd", "mRl: " + mRl.getParent());

        /*View viewT = LayoutInflater.from(this).inflate(R.layout.test, mRl, true);
        LinearLayout ll = viewT.findViewById(R.id.ccc);
        Log.i("zxd", "---: " + viewT.getParent());
        Log.i("zxd", "---: " + viewT.getParent().getParent());
        Log.i("zxd", "---: " + viewT.getParent().getParent().getParent());
        Log.i("zxd", "---: " + viewT.getParent().getParent().getParent().getParent());
        Log.i("zxd", "---: " + viewT.getParent().getParent().getParent().getParent().getParent());
        tv.setOnClickListener(v -> {
            mRl.removeView(viewT);//单独的移除布局，移除不掉
            mRl.removeView(ll);
            Log.i("zxd", "onCreate: 1");
        });*/

        /*View viewF = LayoutInflater.from(this).inflate(R.layout.test, mRl, false);
        LinearLayout ll = viewF.findViewById(R.id.ccc);
        mRl.addView(viewF);
        Log.i("zxd", "---: " + viewF.getParent());
        Log.i("zxd", "---: " + viewF.getParent().getParent());
        Log.i("zxd", "---: " + viewF.getParent().getParent().getParent());
        Log.i("zxd", "---: " + viewF.getParent().getParent().getParent().getParent());
        Log.i("zxd", "---: " + viewF.getParent().getParent().getParent().getParent().getParent());
        tv.setOnClickListener(v -> mRl.removeView(viewF));*/

        /*View viewN = LayoutInflater.from(this).inflate(R.layout.test, null, false);
        mRl.addView(viewN);
        Log.i("zxd", "---: " + viewN.getParent());
        Log.i("zxd", "---: " + viewN.getParent().getParent());
        Log.i("zxd", "---: " + viewN.getParent().getParent().getParent());
        Log.i("zxd", "---: " + viewN.getParent().getParent().getParent().getParent());
        Log.i("zxd", "---: " + viewN.getParent().getParent().getParent().getParent().getParent());
        tv.setOnClickListener(v -> mRl.removeView(viewN));*/

        View viewNA = LayoutInflater.from(this).inflate(R.layout.test, mRl);
        Log.i("zxd", "---: " + viewNA.getParent());
        Log.i("zxd", "---: " + viewNA.getParent().getParent());
        Log.i("zxd", "---: " + viewNA.getParent().getParent().getParent());
        Log.i("zxd", "---: " + viewNA.getParent().getParent().getParent().getParent());
        Log.i("zxd", "---: " + viewNA.getParent().getParent().getParent().getParent().getParent());
        tv.setOnClickListener(v -> mRl.removeView(viewNA));

        //补充方法
//        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//        viewN.inflate()
    }
}
